const { app, BrowserWindow, Menu, globalShortcut } = require('electron')

function createWindow () {
  const win = new BrowserWindow({
    width: 800,
    height: 600,
    icon: './favicon.ico',
    titleBarStyle: 'hidden',
    webPreferences: {
      nodeIntegration: true
    }
  });

  const template = [
    {
      label: "首页",
      submenu: [
        {
          label: "会员中心",
          click: () => {
            var win = new BrowserWindow({
              width: 500,
              height: 500,
              webPreferences: {
                nodeIntegration: true
              }
            })
            win.loadFile('./pro.html');
            win.on('closed',()=>{
                win = null
            })
          },
        },
        {
          label: "商品种类",
          click: () => {
            win.reload();
          },
        },
      ],
    },
    {
      label: "咨询中心",
      submenu: [
        {
          label: "人工客服",
          click() {
            win.webContentsK
          }
        },
        {type: 'separator'},
        {
          label: "打开控制台",
          click() {
            win.webContents.openDevTools()
          }
        },
      ],
    },
  ];
  const m = Menu.buildFromTemplate(template)

  Menu.setApplicationMenu(m);

  globalShortcut.register('CommandOrControl+Shift+i', function () {
    win.webContents.openDevTools()
  })
  
  win.loadFile('index.html')
}

app.whenReady().then(createWindow)

app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') {
    app.quit()
  }
})

app.on('activate', () => {
  if (BrowserWindow.getAllWindows().length === 0) {
    createWindow()
  }
})
